//package cn.microservices.shpplychain.gateway.config;
//
//import com.fasterxml.jackson.annotation.JsonAutoDetect;
//import com.fasterxml.jackson.annotation.PropertyAccessor;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.data.redis.serializer.*;
//
//import java.io.Serializable;
//
//@Configuration
//public class RedisTemplateConfig {
//
//    @Autowired
//    private RedisConnectionFactory redisConnectionFactory;
//
//    /**
//     * StringRedisSerializer() 序列化
//     *
//     * @return
//     */
//    @Bean(name = "strRedisTemplate")
//    public RedisTemplate<String, String> strRedisTemplate() {
//        RedisTemplate<String, String> template = new StringRedisTemplate();
//        template.setConnectionFactory(redisConnectionFactory);
//        return template;
//    }
//
////    @Bean(name = "redisTemplate")
////    public RedisTemplate redisTemplate() {
////        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
////        redisTemplate.setKeySerializer(new StringRedisSerializer()); // key的序列化类型
////        redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); // value的序列化类型
////        redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); // hash value的序列化类型
////        redisTemplate.setConnectionFactory(redisConnectionFactory);
////
////        return redisTemplate;
////    }
//
////    @Bean(name = "redisTemplate")
////    public RedisTemplate redisTemplate() {
////        RedisTemplate<String, Object> template = new RedisTemplate<>();
////        RedisSerializer<String> redisSerializer = new StringRedisSerializer();
////        template.setConnectionFactory(redisConnectionFactory);
////        //key序列化方式
////        template.setKeySerializer(redisSerializer);
////        //value序列化
////        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
////        //value hashmap序列化
////        template.setHashValueSerializer(redisSerializer);
////        return template;
////    }
//    @Bean(name = "redis")
//    public RedisTemplate redisTemplate() {
//        RedisTemplate  template = new RedisTemplate();
//        JdkSerializationRedisSerializer jackson2JsonRedisSerializer = new JdkSerializationRedisSerializer();
//        template.setConnectionFactory(redisConnectionFactory);
//        //解决redis redistemplate KEY为字符串是多双引号
//        template.setKeySerializer(new StringRedisSerializer());
//        template.setValueSerializer(jackson2JsonRedisSerializer);
//        template.setHashKeySerializer(jackson2JsonRedisSerializer);
//        template.setHashValueSerializer(jackson2JsonRedisSerializer);
//        template.afterPropertiesSet();
//        return template;
//    }
//
//    @Bean(name = "objectRedisTemplate")
//    public RedisTemplate<String, Object> objectRedisTemplate() {
//        RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
//        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = getJackson2JsonRedisSerializer();
//        template.setConnectionFactory(redisConnectionFactory);
//        //解决redis redistemplate KEY为字符串是多双引号
//        template.setKeySerializer(new StringRedisSerializer());
//        template.setValueSerializer(jackson2JsonRedisSerializer);
//        template.setHashKeySerializer(jackson2JsonRedisSerializer);
//        template.setHashValueSerializer(jackson2JsonRedisSerializer);
//        template.afterPropertiesSet();
//        return template;
//    }
//
//    @Bean(name = "integerRedisTemplate")
//    public RedisTemplate<String, Integer> integerRedisTemplate() {
//        RedisTemplate<String, Integer> template = new RedisTemplate<String, Integer>();
//        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = getJackson2JsonRedisSerializer();
//
//        template.setConnectionFactory(redisConnectionFactory);
//        //解决redis redistemplate KEY为字符串是多双引号
//        template.setKeySerializer(new StringRedisSerializer());
//        template.setValueSerializer(jackson2JsonRedisSerializer);
//        template.setHashKeySerializer(jackson2JsonRedisSerializer);
//        template.setHashValueSerializer(jackson2JsonRedisSerializer);
//        template.afterPropertiesSet();
//        return template;
//    }
//
//
//    private static Jackson2JsonRedisSerializer<Object> getJackson2JsonRedisSerializer() {
//        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
//        ObjectMapper om = new ObjectMapper();
//        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//        jackson2JsonRedisSerializer.setObjectMapper(om);
//        return jackson2JsonRedisSerializer;
//    }
//
//}
